<template>
  <div class="printForm">
    <div class="area-header">
      <span class="area-header-title">{{ $t('申请单') }}</span>
    </div>
    <table class="printTable">
      <tr>
        <td class="tit">{{ $t('标题') }}</td>
        <td>{{ form.title }}</td>
        <td class="tit">{{ $t('上市项目') }}</td>
        <td>{{ form.dealName }}</td>
      </tr>
      <tr>
        <td class="tit">{{ $t('证券代码') }}</td>
        <td>
          {{ form.stockCode }}
        </td>
        <td class="tit">{{ $t('我方持有总股数(万股)') }}</td>
        <td>
          {{ moneyFormat(form.shareHold) }}
        </td>
      </tr>
      <tr>
        <td class="tit">{{ $t('持股比例(%)') }}</td>
        <td>{{ moneyFormat(form.shareRate) }}</td>
        <td class="tit">{{ $t('减持股数不超过(万股)') }}</td>
        <td>{{ moneyFormat(form.shareNotExceeding) }}</td>
      </tr>
      <tr>
        <td class="tit">{{ $t('减持比例不超过(%)') }}</td>
        <td>
          {{ moneyFormat(form.rateNotExceeding, 'rate') }}
        </td>
        <td class="tit">{{ $t('预计公告发布日期') }}</td>
        <td>{{ parseTime(form.releaseDate) }}</td>
      </tr>
      <tr>
        <td class="tit">{{ $t('交易方式') }}</td>
        <td>
          <span v-for="(v, index) in form.tradingWayArray" :key="index">
            {{ wayFormat(v) }},
          </span>
        </td>
        <td class="tit">{{ $t('预计减持日期') }}</td>
        <td>{{ parseTime(form.reducingDateStart) }} / {{ parseTime(form.reducingDateEnd) }}</td>
      </tr>
      <tr>
        <td class="tit">{{ $t('公告内容') }}</td>
        <td colspan="3">{{ form.context }}</td>
      </tr>
    </table>

    <!-- 附件列表 -->
    <FileView :list.sync="form.fileList" data-type="listed_reducing_notice" :btn-show="!otherBtnHide" :business-id="form.dealId" />

  </div>
</template>

<script>
import { getListedReducingNotice } from '@/api/deal/listed/reducing/listedReducingNotice'
import { getListedDeal } from '@/api/deal/listed/base/listedDeal'
export default {
  components: {
  },
  data() {
    return {
      form: {
        tradingWayArray: [],
        fileList: []
      },
      tradingWayOptions: []
    }
  },
  mounted() {
    this.$bus.$emit('async_done')
    this.getDicts('listed_trading_way').then(response => {
      this.tradingWayOptions = response.data
    })
  },
  methods: {
    // 初始化数据
    init(data) {
      if (data != null && data.id !== undefined) {
        getListedReducingNotice(data.id).then(response => {
          this.form = response.data
          // 设置交易方式
          if (this.form.tradingWay !== null && this.form.tradingWay !== '') {
            var arr = this.form.tradingWay.split(',')
            this.$set(this.form, 'tradingWayArray', arr)
          }
          // 获取项目相关数据
          this.selectTree()
        })
      }
    },
    // 选择上市项目事件，获取选择的项目的其他关联数据
    selectTree() {
      // 获取关联数据
      getListedDeal(this.form.listedId).then(res => {
        this.form.stockCode = res.data.stockCode
        this.form.shareHold = res.data.shareHold
        this.form.shareRate = res.data.shareRate
        this.form.totalEquity = res.data.totalEquity
        this.form.dealId = res.data.dealId
        this.form.dealName = res.data.dealName
        this.form.market = res.data.market
        this.calcRateNotExceeding()
      })
    },
    // 计算减持比例不超过百分比 = 减持股数 / 总股本
    calcRateNotExceeding() {
      if (this.form.totalEquity !== undefined && this.form.shareNotExceeding && this.form.totalEquity !== 0) {
        this.form.rateNotExceeding = (this.form.shareNotExceeding / this.form.totalEquity * 100).toFixed(4)
      }
    },
    wayFormat(row) {
      return this.selectDictLabel(this.tradingWayOptions, row)
    }

  }

}
</script>
